package com.hdu.hystrix;

import com.hdu.context.FullLinkContext;
import com.hdu.context.FullLinkContextHolder;

import java.util.concurrent.Callable;

public class DelegatingFullLinkContextCallable <V> implements Callable<V> {


    /**
     * 原始全链路压测上下文
     */
    private final FullLinkContext fullLinkContext;

    /**
     * 原始执行逻辑
     */
    private final Callable<V> original;


    public DelegatingFullLinkContextCallable(Callable<V> callable, FullLinkContext fullLinkContext) {
           this.original = callable;
           this.fullLinkContext = fullLinkContext;
    }


    @Override
    public V call() throws Exception {
        FullLinkContextHolder.clear();
        FullLinkContextHolder.markFullLinkStress(this.fullLinkContext);
        try {
            return this.original.call();
        }
        finally {
            FullLinkContextHolder.clear();
        }
    }
}
